package factory;


import javax.inject.Inject;
import javax.inject.Singleton;

import service.BeWeekly;
import service.CommissionedService;
import service.ContractorService;
import service.EmployeeService;
import service.Monthly;
import service.SalariedService;
import service.UnionAssociationService;
import dao.PaymentReportDao;
import dao.SalesCardDao;
import dao.TimeCardDao;
import entity.Commissioned;
import entity.Contractor;
import entity.Employee;
import entity.Salaried;
import entity.SalesCard;
@Singleton
public class EmployeeServiceFactory {
	@Inject AssociationServiceFactory factory;
	@Inject SalesCardDao salesCardDao;
	@Inject TimeCardDao timeCardDao;
	@Inject PaymentReportDao payReportDao;
	public EmployeeService createEmployeeService(Employee employee) {	
		EmployeeService service=null;
		if(employee instanceof Salaried){
			service=new SalariedService((Salaried)employee,payReportDao.lastPayDay(employee));
		}
		if (employee instanceof Contractor){
			((Contractor)employee).setTimeCards(timeCardDao.listTime((Contractor)employee));
			service=new ContractorService((Contractor)employee,payReportDao.lastPayDay(employee));
		}
		 if (employee instanceof Commissioned){
			 ((Commissioned)employee).setSalesCards(salesCardDao.listSales((Commissioned)employee));
			 service=new CommissionedService((Commissioned)employee,payReportDao.lastPayDay(employee));

			 Monthly monthly=new Monthly(payReportDao.lastPayDay(employee));
			 if(monthly.checkPay()){
				 service=new SalariedService((Salaried)employee,payReportDao.lastPayDay(employee));
			 }
			 BeWeekly beeBeWeekly=new BeWeekly(payReportDao.lastPayDay(employee));
			 if(beeBeWeekly.checkPay()){
			 ((Commissioned)employee).setSalesCards(salesCardDao.listSales((Commissioned)employee));
			 service=new CommissionedService((Commissioned)employee,payReportDao.lastPayDay(employee));
			 }
			
		}
		service.setAssociationService(factory.CreateAssociationService(employee,payReportDao.lastPayDay(employee)));
		return service;
	}

}
